package com.pureut.order.util;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.pureut.order.dto.ConverterMqDto;
import com.pureut.order.dto.CustomerManagementMqDto;
import com.pureut.order.dto.OrderSupplierManagementMqDto;
import com.sale.common.core.message.RocketMqUtils;
import org.springframework.beans.factory.annotation.Value;

/**
 * @Description 发送管理类（加工商、供应商、客户）
 * @Param MaterialMq
 * @Date 23-02-20
 * @Author hl
 **/
public class VariousMqUtil {

    @Value("${rocketmq.name-server}")
    private static String mqServer;

    @Value("${producer.group}")
    private static String mqGroup;

    @Value("${producer.send-message-timeout}")
    private static int mqTimeOut;

    /**
     * 加工商修改消息发送(mq)
     */
    public static void converterManagementMqSend(ConverterMqDto mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "converter_management",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 加工商消息发送删除(mq)
     */
    public static void converterManagementMqSendDelete(ConverterMqDto mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "converter_management_delete",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 供应商修改消息发送(mq)
     */
    public static void orderSupplierManagementMqSend(OrderSupplierManagementMqDto mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "orderSupplierManagement",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 供应商修改消息发送删除(mq)
     */
    public static void orderSupplierManagementMqSendDelete(OrderSupplierManagementMqDto mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "orderSupplierManagementDelete",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 客户修改消息发送(mq)
     */
    public static void customerManagementMqSend(CustomerManagementMqDto mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "customer_management",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 客户删除消息发送(mq)
     */
    public static void customerManagementMqSendDelete(CustomerManagementMqDto mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "customer_management_delete",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

}
